package sketch.semantics;

import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

import sketch.doc.Sketch;

public class SemanticGraph {

	private Map<Integer, Concept> id2concept;

	private Sketch sketch;

	private Vector<Concept> concepts;

	private Vector<Relation> relations;

	public SemanticGraph(Sketch sketch) {
		this.sketch = sketch;

		id2concept = new HashMap<Integer, Concept>();
		concepts = new Vector<Concept>();
		relations = new Vector<Relation>();
	}

	public Vector<Concept> getConcepts() {
		return concepts;
	}

	public Vector<Relation> getRelations() {
		return relations;
	}

	public Sketch getSketch() {
		return sketch;
	}

	public void addConcept(Concept concept) {
		id2concept.put(new Integer(concept.getShapeId()), concept);
		getConcepts().add(concept);
	}

	public Concept getConceptByShapeId(int id) {
		return id2concept.get(new Integer(id));
	}

	public void addRelation(Relation relation) {
		getRelations().add(relation);
	}

	public static SemanticGraph generateSemanticGraph(Sketch sketch, SGGenerator sgg) {
		SemanticGraph sg = new SemanticGraph(sketch);
		sgg.generateOn(sg);
		return sg;
	}

	public String toString() {
		StringBuffer sb = new StringBuffer();

		sb.append("Concepts -----\n");
		for (Concept con : getConcepts()) {
			sb.append(con.toString());
			sb.append("\n");
		}

		sb.append("Relations ----\n");
		for (Relation rl : getRelations()) {
			sb.append(rl.toString());
			sb.append("\n");
		}

		return sb.toString();
	}

}
